home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
msdos
/
utils
/
cad3d2ra.zoo
/
cad3dobj.h
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-14
|
4KB
|
117 lines
/*
* cad3d2obj - the Atari CAD-3D file format
* $Id: cad3dobj.h,v 1.1 1994/03/14 15:23:17 herborth Exp $
*
* Chris Herborth
* March 6/94
*
* Here is a handy struct or two for dealing with Atari CAD-3D 2.x files.
* See the end of this file for function prototypes!
*
* $Log: cad3dobj.h,v $
* Revision 1.1 1994/03/14 15:23:17 herborth
* Initial revision
*
*/
#define CAD3D_MAGIC 0x3d02
/* The header of a CAD-3D 2.x file (*.3D2) has this structure: */
typedef struct cad3d_header
{
short file_id; /* should equal 0x3d02 */
short num_objects; /* 1-40 objs/file */
short light_a_flag; /* Are the lights on? 0=off, 1=on */
short light_b_flag;
short light_c_flag;
short light_a_bright; /* Light brightness, scale 0-7 */
short light_b_bright;
short light_c_bright;
short ambient_bright; /* Ambient light brightness */
short light_a_z; /* Light Z position -50 to +50 */
short light_b_z;
short light_c_z;
short light_a_y; /* Light Y position */
short light_b_y;
short light_c_y;
short light_a_x; /* Light X position */
short light_b_x;
short light_c_x;
/* The CAD-3D format docs I have are _wrong_ here! They said these */
/* two items had 32 words, but in reality, they only have 16... */
short obj_palette[16];
short colour_group[16];
short palette_type; /* 0=7-shades, 1=14-shades, 2=custom */
short wireframe_colour; /* Wireframe line colour (1-15) */
short outline_colour; /* Outline line colour (0-15) */
char reserved[150]; /* For future expansion (ha!) */
} CAD3D_HEADER;
/* Each vertex in an object is made up of three points; this is a fixed- */
/* point representation from -50.00 to 50.00. Convert each short to a */
/* double and divide by 100.0 to get the "actual" value. */
typedef struct cad3d_vertex
{
short x;
short y;
short z;
} CAD3D_VERTEX;
/* Each triangle in the file is defined by three points; each point is */
/* an index into the array of vertices. */
/* colour_edge & 0x00ff = 1-15, the face colour */
/* if( colour_edge & 0x0100 ) - draw CA in lines-only mode */
/* if( colour_edge & 0x0200 ) - draw BC in lines-only mode */
/* if( colour_edge & 0x0400 ) - draw AB in lines-only mode */
typedef struct cad3d_triangle
{
short index_a; /* Index into the vertices array for point A */
short index_b;
short index_c;
short colour_edge;
} CAD3D_TRIANGLE;
/* Each object in the file is made up like this. */
typedef struct cad3d_object
{
char name[9]; /* object name, 8 chars + NULL terminator */
unsigned short num_vertices; /* number of vertices in the object, <= 15000 */
CAD3D_VERTEX *vertices; /* malloc'd array of vertices */
unsigned short num_triangles; /* number of triangles in the object, <= 30000 */
CAD3D_TRIANGLE *triangles; /* malloc'd array of vertices */
} CAD3D_OBJECT;
/* This is a "standard" RGB triad struct; we'll use this to easily convert */
/* Atari ST BIOS colours into RGB ranging from 0.0 to 1.0... If this was */
/* C++ instead of just C, you could have class rgb_alpha: public rgb_triad */
typedef struct rgb_triad
{
float red;
float green;
float blue;
} RGB_TRIAD;
/* Function prototypes for cad3dobj.c... */
short get_cad3d_header( FILE *fp, CAD3D_HEADER *head );
short dump_cad3d_header( FILE *fp, const CAD3D_HEADER *head );
short get_cad3d_object( FILE *fp, CAD3D_OBJECT *obj );
short dump_cad3d_object( FILE *fp, const CAD3D_OBJECT *obj );
short get_cad3d_vertex( FILE *fp, CAD3D_VERTEX *vert );
short get_cad3d_triangle( FILE *fp, CAD3D_TRIANGLE *tri );
short cad3d_triangle_colour( const CAD3D_HEADER *head,
const CAD3D_TRIANGLE *tri );
short atari2rgb( const short atari, RGB_TRIAD *rgb );
/* Damn those foolish Intel folks... */
#ifdef LITTLE_ENDIAN
short swap_short( const short s );
#endif